#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

while True:
    with display_block('Entradas'):
        k = One * oneof(-1, 1) * oneof(1, 2, 3, 4, 5) / oneof(2, 3)
        a = One * oneof(-1, 1) * oneof(1, 2, 3, 4, 5) / oneof(2, 3)
        vars = (x, y)
        func = ((x - a) ** 2 + 2 * a * x * y / k)

    with display_block('Resultados'):
        p1 = (0, k)
        _pts = set([p1, (k, 0), (a, 0) if oneof(True, False) and a != k else (0, 0), (0, a)])
        iter = 0
        while len(_pts) < 7:
            iter += 1
            if iter > 50:
                break
            aa, bb = oneof(*_pts)
            if oneof(True, False, False):
                aa *= One * oneof(-1, -1, -1, -1, 0, 0, 1, 2, 3) / oneof(-1, -1, -1, -1, 1, 2, 3)
            elif oneof(True, False):
                bb *= One * oneof(-1, -1, -1, -1, 0, 0, 1, 2, 3) / oneof(-1, -1, -1, -1, 1, 2, 3)
            else:
                aa, bb = bb, aa
            if (aa, bb) not in _pts:
                _pts.add((aa, bb))
        _pts.remove(p1)
        p2, p3, p4, p5, p6, p7 = _pts

        # Define tipos errados
        tipos = set(u'mínimo máximo sela falha'.split())
        tipo = u'sela'
        tipos.remove(tipo)
        tipoE1 = tipos.pop()
        tipoE2 = tipos.pop()
        tipoE3 = tipos.pop()

        if len(set([p1, p2, p3, p4, p5, p6, p7])) != 7:
            continue
        else:
            break
